package Algorithm.Othes;

//https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/
//807. 保持城市天际线
public class Leetcode807 {
    class Solution {
        public int maxIncreaseKeepingSkyline(int[][] grid) {
            int[] vMartrix = new int[grid[0].length];
            int[] hMartrix = new int[grid.length];

            for(int i=0;i<grid.length;i++){
                for(int j=0;j<grid[i].length;j++){
                    hMartrix[i] = Math.max(hMartrix[i], grid[i][j]);
                    vMartrix[j] = Math.max(vMartrix[j], grid[i][j]);
                }
            }
            int sum = 0;
            for(int i=0;i<grid.length;i++){
                for(int j=0;j<grid[i].length;j++){
                    int minTemp = Math.min(hMartrix[i],vMartrix[j]);
                    sum = sum + minTemp - grid[i][j];
                }
            }

            return sum;
        }
    }
}
